package lnx

/*
#cgo CPPFLAGS: -fPIC -I../index
#cgo linux LDFLAGS: -fPIC -L${SRCDIR} -Wl,-rpath ${SRCDIR} -lhs_trade -lstdc++

#include "HSDataType.h"
#include "HSStruct.h"
void* tCreateApi();
void* tCreateSpi();
void* tGetVersion();
[[ range .Fn ]]// [[ .Comment ]]
void* t[[ .FuncName ]]([[ range $i, $v := .FuncFields ]][[ if gt $i 0 ]], [[ end ]][[ .FieldType|struct_Type ]] [[ .FieldName ]][[ if eq .FieldName "*ppInstrumentID" ]][][[ end ]][[end]]);
[[ end ]]
[[ range .On ]]// [[ .Comment ]]
void tSetOn[[ .FuncName ]](void*, void*);
void t[[ .FuncName ]](void* spi[[ range $i, $v := .FuncFields ]], [[ .FieldType|struct_Type ]] [[ .FieldName ]][[ end ]]);
[[ end ]]
#include <stdlib.h>
#include <stdint.h>
*/
import "C"

import (
	"unsafe"

	"gitee.com/haifengat/gohs/def"
)

var t *Trade

// Trade 交易接口
type Trade struct {
	//gohs.HFTrade
	spi, api unsafe.Pointer
	passWord string // 密码

    [[ range .On]]// [[ .Comment ]]
    On[[ .FuncName ]] func([[ range $i,$v := .FuncFields ]][[ if gt $i 0 ]], [[ end ]][[ .FieldName|trimStar ]] [[ .FieldType|ctp_type ]][[ end ]])
    [[ end]]
}

// NewTrade 实例化
func NewTrade() *Trade {
	t = new(Trade)

	t.api = C.tCreateApi()
	t.spi = C.tCreateSpi()
	C.tRegisterSpi(t.api, t.spi)

    [[ range .On ]]C.tSetOn[[ .FuncName ]](t.spi, C.t[[ .FuncName ]])
    [[ end ]]
	return t
}
[[ range .On ]]
//export t[[ .FuncName ]]
func t[[ .FuncName ]](spi unsafe.Pointer[[ range $i, $v := .FuncFields ]], [[ .FieldName|trimStar ]] [[ .FieldType|C_struct]][[ end ]]) {
	if t.On[[ .FuncName ]] != nil{
        t.On[[ .FuncName ]]([[ range $i,$v := .FuncFields ]][[ if gt $i 0 ]], [[ end ]][[ ctp_param .FieldType .FieldName ]][[ end ]])
    }
}
[[ end ]]
